from aip import AipOcr

""" 你的 APPID AK SK """
APP_ID = '16375016'
API_KEY = 'CQgoSnEq902TsagaYt0Ub9iN'
SECRET_KEY = 'llGmluwd49dUZPGv5VH7WKV5XmqjXYer'
client = AipOcr(APP_ID, API_KEY, SECRET_KEY)

""" 读取图片 """
def get_file_content(filepath):
    with open(filepath, 'rb') as fp:
        return fp.read()


def pictotxt(filepath):
    image = get_file_content(filepath)
    """ 调用通用文字识别, 图片参数为本地图片 """
    txt = client.basicGeneral(image)
    return txt

def pictotxt2(filepath):
    image = get_file_content(filepath)
    """ 调用通用文字识别高精度版, 图片参数为本地图片 """
    txt = client.basicAccurate(image)
    return txt
# if __name__ == "__main__":
#    main()

# """ 如果有可选参数 """
# options = {}
# options["language_type"] = "CHN_ENG"
# options["detect_direction"] = "true"
# options["detect_language"] = "true"
# options["probability"] = "true"
#
# """ 带参数调用通用文字识别, 图片参数为本地图片 """
# print(client.basicGeneral(image, options))

# url = "http//www.x.com/sample.jpg"
#
# """ 调用通用文字识别, 图片参数为远程url图片 """
# print(client.basicGeneralUrl(url))
#
# """ 如果有可选参数 """
# options = {}
# options["language_type"] = "CHN_ENG"
# options["detect_direction"] = "true"
# options["detect_language"] = "true"
# options["probability"] = "true"
#
# """ 带参数调用通用文字识别, 图片参数为远程url图片 """
# client.basicGeneralUrl(url, options)

